package cn.korilweb.demodictionary.controller;

import cn.korilweb.demodictionary.entity.Result;
import cn.korilweb.demodictionary.entity.dto.DictDTO;
import cn.korilweb.demodictionary.entity.dto.DictOrderDTO;
import cn.korilweb.demodictionary.entity.dto.DictStatusDTO;
import cn.korilweb.demodictionary.entity.dto.DictTypeDTO;
import cn.korilweb.demodictionary.entity.vo.DictInfoVO;
import cn.korilweb.demodictionary.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DJH
 * @date 2021-10-26 21:27:11
 */
@RestController
public class DictController {

    @Autowired
    private DictService dictService;

    @GetMapping("/dictionaries")
    public Result<List<DictInfoVO>> getDict() {
        List<DictInfoVO> res = dictService.getTreeList();
        return Result.ok(res);
    }

    @PostMapping("/dictionaries")
    public Result<?> addDict(@RequestBody DictDTO dictDTO) {
        dictService.addDict(dictDTO);
        return Result.ok("新增字典成功");
    }

    @PostMapping("/dictionaries/type")
    public Result<?> addType(@RequestBody DictTypeDTO dictTypeDTO) {
        dictService.addType(dictTypeDTO);
        return Result.ok("新增分类成功");
    }

    @PutMapping("/dictionaries/{infoId}")
    public Result<?> modifyDict(@PathVariable("infoId") Integer infoId, @RequestBody DictDTO dictDTO) {
        dictService.modifyDict(infoId, dictDTO);
        return Result.ok("修改信息成功");
    }

    @PutMapping("/dictionaries/order")
    public Result<?> changeOrder(@RequestBody DictOrderDTO dictOrderDTO) {
        dictService.changeOrder(dictOrderDTO);
        return Result.ok("修改顺序成功");
    }

    @PutMapping("/dictionaries/status")
    public Result<?> changeStatus(@RequestBody DictStatusDTO dictStatusDTO) {
        dictService.changeStatus(dictStatusDTO);
        return Result.ok("修改状态成功");
    }

    @DeleteMapping("/dictionaries/{infoId}")
    public String removeDict(@PathVariable("infoId") Integer infoId) {
        return "ok";
    }
}
